<template>
  <div>
    <el-switch v-if="row.key == 'local'" v-model="status" :disabled="row.status == 1" :active-value="1" :inactive-value="0" @change="changeStatus" />
    <el-switch v-else v-model="status" :disabled="disabled" :active-value="1" :inactive-value="0" @change="changeStatus" />
  </div>
</template>

<script>
export default {
  props: {
    row: {
      type: Object,
      default: _ => {
        return {};
      }
    }
  },
  inject: ['reload'],
  data() {
    return {
      disabled: false,
      status: this.row.status
    };
  },
  methods: {
    changeStatus: function(value) {
      const txt = value ? '启用前请先确认配置信息是否正确，否则将可能导致无法唤起支付功能' : '关闭该支付方式后，将无法使用该方式支付';
      this.$box
        .confirm(txt)
        .then(() => {
          const data = {
            status: value ? 1 : 0
          };
          this.disabled = true;
          this.$http.post(
            '/admin/system/package/payment/' + this.row.key + '/status',
            data,
            response => {
              this.disabled = false;
            },
            error => {
              this.disabled = false;
              this.$message.error(error.msg);
            },
            false
          );
        })
        .catch(() => {
          this.status = value == 1 ? 0 : 1;
        });
    }
  }
};
</script>

<style></style>
